﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using QunYing.Model;
namespace QunYing.BLL
{
    /// <summary>
    /// OrderInfo
    /// </summary>
    public partial class OrderInfo
    {
        private readonly QunYing.DAL.OrderInfo dal = new QunYing.DAL.OrderInfo();
        public OrderInfo()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int 订单ID, string 订单编号)
        {
            return dal.Exists(订单ID, 订单编号);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(QunYing.Model.OrderInfo model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(QunYing.Model.OrderInfo model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int 订单ID)
        {

            return dal.Delete(订单ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int 订单ID, string 订单编号)
        {

            return dal.Delete(订单ID, 订单编号);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string 订单IDlist)
        {
            return dal.DeleteList(订单IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public QunYing.Model.OrderInfo GetModel(int 订单ID)
        {

            return dal.GetModel(订单ID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public QunYing.Model.OrderInfo GetModelByCache(int 订单ID)
        {

            string CacheKey = "OrderInfoModel-" + 订单ID;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(订单ID);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (QunYing.Model.OrderInfo)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<QunYing.Model.OrderInfo> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<QunYing.Model.OrderInfo> DataTableToList(DataTable dt)
        {
            List<QunYing.Model.OrderInfo> modelList = new List<QunYing.Model.OrderInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                QunYing.Model.OrderInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new QunYing.Model.OrderInfo();
                    if (dt.Rows[n]["订单ID"] != null && dt.Rows[n]["订单ID"].ToString() != "")
                    {
                        model.订单ID = int.Parse(dt.Rows[n]["订单ID"].ToString());
                    }
                    if (dt.Rows[n]["订单编号"] != null && dt.Rows[n]["订单编号"].ToString() != "")
                    {
                        model.订单编号 = dt.Rows[n]["订单编号"].ToString();
                    }
                    if (dt.Rows[n]["订单日期"] != null && dt.Rows[n]["订单日期"].ToString() != "")
                    {
                        model.订单日期 = DateTime.Parse(dt.Rows[n]["订单日期"].ToString());
                    }
                    if (dt.Rows[n]["总价"] != null && dt.Rows[n]["总价"].ToString() != "")
                    {
                        model.总价 = decimal.Parse(dt.Rows[n]["总价"].ToString());
                    }
                    if (dt.Rows[n]["总积分"] != null && dt.Rows[n]["总积分"].ToString() != "")
                    {
                        model.总积分 = int.Parse(dt.Rows[n]["总积分"].ToString());
                    }
                    if (dt.Rows[n]["赠送总积分"] != null && dt.Rows[n]["赠送总积分"].ToString() != "")
                    {
                        model.赠送总积分 = int.Parse(dt.Rows[n]["赠送总积分"].ToString());
                    }
                    if (dt.Rows[n]["用户ID"] != null && dt.Rows[n]["用户ID"].ToString() != "")
                    {
                        model.用户ID = dt.Rows[n]["用户ID"].ToString();
                    }
                    if (dt.Rows[n]["收件人"] != null && dt.Rows[n]["收件人"].ToString() != "")
                    {
                        model.收件人 = dt.Rows[n]["收件人"].ToString();
                    }
                    if (dt.Rows[n]["联系电话"] != null && dt.Rows[n]["联系电话"].ToString() != "")
                    {
                        model.联系电话 = dt.Rows[n]["联系电话"].ToString();
                    }
                    if (dt.Rows[n]["收件地址"] != null && dt.Rows[n]["收件地址"].ToString() != "")
                    {
                        model.收件地址 = dt.Rows[n]["收件地址"].ToString();
                    }
                    if (dt.Rows[n]["用户留言"] != null && dt.Rows[n]["用户留言"].ToString() != "")
                    {
                        model.用户留言 = dt.Rows[n]["用户留言"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

